#!/usr/bin/env python3
# -*- coding:utf-8 -*-
from prettytable import PrettyTable


class StringUtil:
    # 使用prettytable库的表格输出
    __table = PrettyTable(['演出名称', '类型', '图片地址', '状态', '地址', '时间', '价格'])
    __table.align = 'l'

    @staticmethod
    def clean_str(s: str) -> str | None:
        if s is not None:
            s_trimmed = s.strip()
            if len(s_trimmed) > 0:
                return s_trimmed

        print("输入为空！！！")
        return None
    @staticmethod
    def clean_price(s: str) -> str | None:
        if s is not None:
            s_trimmed = s.strip()
            if len(s_trimmed) > 0:
                return s_trimmed

        return None

    # 判断城市城市输入
    @staticmethod
    def clean_city(city_dict: dict, input_city) -> str | None:
        for city in city_dict:
            if input_city == city and StringUtil.clean_str(input_city):
                return city_dict[city], city

        print("请输入正确的城市名！！！")
        return None

    # 判断演出分类输入
    @staticmethod
    def clean_performance(performance_dict: dict, input_performance) -> str | None:
        for performance in performance_dict:
            if input_performance == performance and StringUtil.clean_str(input_performance):
                return performance_dict[performance], performance

        print("请输入正确的演出分类名！！！")
        return None

    # 判断时间分类输入
    @staticmethod
    def clean_time(time_dict: dict, input_time: str, city_name: str) -> str | None:
        if input_time == '全部':
            return city_name, input_time
        for time in time_dict:
            if input_time == time and StringUtil.clean_str(input_time):
                return time_dict[time], input_time

        print("请输入正确的时间分类名！！！")
        return None

    # 做出选择分类
    @staticmethod
    def choose_performance(choose_sort: str) -> str | None:
        if StringUtil.clean_str(choose_sort) == "选择演出分类":
            return StringUtil.clean_str(input("\r\n>>>"))
        elif StringUtil.clean_str(choose_sort) == "选择城市分类":
            return StringUtil.clean_str(input("\r\n>>>"))
        elif StringUtil.clean_str(choose_sort) == "选择时间分类":
            return StringUtil.clean_str(input("\r\n>>>"))

    # 输出爬到的信息
    @staticmethod
    def add_obj_to_table(obj_name: list):
        try:
            for obj in obj_name:
                tmp_obj_list = [
                    obj.name,
                    obj._type,
                    obj.image_url,
                    obj.status,
                    obj.address,
                    obj.open_time,
                    obj.price
                ]
                StringUtil.__table.add_row(tmp_obj_list)
            print(StringUtil.__table)
        except TypeError as err:
            print('{}'.format(err))


if __name__ == '__main__':
    pass
